
#ifndef  HELPER_WATCH_CHRONOCLOCK_H
#define  HELPER_WATCH_CHRONOCLOCK_H


#include "helper/watch/IClock.h"
#include <chrono>


namespace helper {
namespace watch {

template<typename Clock = std::chrono::steady_clock>
class ChronoClock : public IClock<typename Clock::time_point, typename Clock::duration> {
public:
    typedef typename Clock::time_point TimePoint; //time_point
    typedef typename Clock::duration  Duration; //duration

    TimePoint init() override{
        return TimePoint(); //epoch
    }
    TimePoint now() override{
       return Clock::now(); 
    }
    const Duration diff(const Timespan<TimePoint> & ts) const override{
        return std::chrono::duration_cast<Duration>(ts.end - ts.start);
    }
};


}// end of namespace watch
}// end of namespace helper

namespace std{
template<typename Rep, typename Period>
ostream & operator <<(ostream & oss, const chrono::duration<Rep, Period> & dur){
    oss << dur.count();
    return oss;
}
template<typename Clock>
ostream & operator <<(ostream & oss, const chrono::time_point<Clock, typename Clock::duration> & tp){
    oss << tp.time_since_epoch();
    return oss;
}
} //end of namespace std

#endif   /* HELPER_WATCH_CHRONOCLOCK_H */
